﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Marmat.Template.WinForm
{
    public partial class BaseEditForm<Entity> : Form, IDocumentEditForm<Entity>, Marmat.Foundation.IEditFormEditorStyle where Entity : new()
    {
        public BaseEditForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 编辑控制器
        /// </summary>
        public IDocumentEditFormController<Entity, Entity[]> Controller { get; set; }

        /// <summary>
        /// 数据源
        /// </summary>
        protected Entity DataSource { get; private set; }

        /// <summary>
        /// 准备编辑时执行
        /// </summary>
        public virtual void Editor()
        {
        }

        /// <summary>
        /// 返回预览时执行
        /// </summary>
        public virtual void Preview()
        {
        }

        /// <summary>
        /// 保存成功后执行。
        /// </summary>
        public virtual void OnSuccess()
        {
        }

        ///// <summary>
        ///// 保存前的校验(默认不校验)。
        ///// </summary>
        ///// <returns></returns>
        //public virtual bool OnVerify()
        //{
        //    return true;
        //}

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="data"></param>
        public new virtual void Load(Entity data)
        {
            this.DataSource = data;
        }

        public bool Verify()
        {
            return true;
        }
    }
}
